﻿package mortal.game.scene3D.display3d.text3d.staticText3d
{
    import __AS3__.vec.*;
    import baseEngine.core.*;
    import baseEngine.system.*;
    import extend.language.*;
    import flash.events.*;
    import flash.utils.*;
    import frEngine.*;
    import frEngine.render.layer.*;
    import mortal.game.scene3D.*;
    import mortal.game.scene3D.display3d.text3d.*;
    import mortal.game.scene3D.display3d.text3d.staticText3d.action.*;

    public class SText3DFactory extends Object
    {
        public const duringFrame:Number = 33;
        private var _scene:GameScene3D;
        public var textMesh3d:SText3DMesh;
        private var _sText3DPool:Array;
        private var _boxPool:Array;
        private var _curUseBoxList:Array;
        private var reg:RegExp;
        private var textReplaceDic:Dictionary;
        public var textMapDic:Dictionary;
        public var numberMapDic:Dictionary;
        public var kuohaoMapDic:Dictionary;
        private var tempVect:Vector.<Stext3DPlace>;
        public static const instance:SText3DFactory = new SText3DFactory;

        public function SText3DFactory()
        {
            var _loc_7:Object = null;
            this._sText3DPool = new Array();
            this._boxPool = new Array();
            this._curUseBoxList = new Array();
            this.textReplaceDic = new Dictionary(false);
            this.textMapDic = new Dictionary(false);
            this.numberMapDic = new Dictionary(false);
            this.kuohaoMapDic = new Dictionary(false);
            this.tempVect = new Vector.<Stext3DPlace>;
            this.textMesh3d = new SText3DMesh(false);
            this.textMesh3d.setLayer(Layer3DManager.text3DLayer, false);
            this.textMesh3d.render = SText3DRender.instance;
            var _loc_1:Array = [];
            _loc_1.push({name:Language.getString(20612), name2:"a", textVo:new TextVo(15, 0, 0, 3, 2)});
            _loc_1.push({name:Language.getString(20613), name2:"b", textVo:new TextVo(18, 0, -8, 3, 2)});
            _loc_1.push({name:Language.getString(20614), name2:"c", textVo:new TextVo(21, 0, -8, 3, 2)});
            _loc_1.push({name:Language.getString(20615), name2:"d", textVo:new TextVo(12, 2, -8, 3, 2)});
            _loc_1.push({name:Language.getString(20616), name2:"e", textVo:new TextVo(15, 2, -8, 3, 2)});
            _loc_1.push({name:Language.getString(20617), name2:"f", textVo:new TextVo(18, 2, -8, 3, 2)});
            _loc_1.push({name:Language.getString(20618), name2:"g", textVo:new TextVo(21, 2, -8, 3, 2)});
            _loc_1.push({name:Language.getString(20619), name2:"h", textVo:new TextVo(12, 4, -8, 3, 2)});
            _loc_1.push({name:Language.getString(20620), name2:"i", textVo:new TextVo(16, 6, 0, 3, 2)});
            var _loc_2:String = "";
            var _loc_3:* = _loc_1.length;
            var _loc_4:int = 0;
            while (_loc_4 < _loc_3)
            {
                
                _loc_7 = _loc_1[_loc_4];
                _loc_2 = _loc_4 == 0 ? (_loc_7.name) : (_loc_2 + "|" + _loc_7.name);
                this.textReplaceDic[_loc_7.name] = _loc_7.name2;
                this.textMapDic[_loc_7.name2] = _loc_7.textVo;
                _loc_4++;
            }
            this.reg = new RegExp(_loc_2, "g");
            this.textMapDic[Language.getString(20621)] = new TextVo(15, 4, 0, 1, 1);
            this.textMapDic[Language.getString(20622)] = new TextVo(16, 4, 0, 1, 1);
            this.textMapDic[Language.getString(20623)] = new TextVo(17, 4, 0, 1, 1);
            this.textMapDic[Language.getString(20624)] = new TextVo(18, 4, 0, 1, 1);
            this.textMapDic[Language.getString(20625)] = new TextVo(19, 4, 0, 1, 1);
            this.textMapDic[Language.getString(20626)] = new TextVo(20, 4, 0, 1, 1);
            this.textMapDic[Language.getString(20627)] = new TextVo(21, 4, 0, 1, 1);
            this.textMapDic[Language.getString(20628)] = new TextVo(22, 4, 0, 1, 1);
            this.textMapDic[Language.getString(20629)] = new TextVo(23, 4, 0, 1, 1);
            this.textMapDic[Language.getString(20630)] = new TextVo(15, 5, 0, 1, 1);
            this.textMapDic[Language.getString(20631)] = new TextVo(16, 5, 0, 1, 1);
            this.textMapDic[Language.getString(20632)] = new TextVo(17, 5, 0, 1, 1);
            this.textMapDic[Language.getString(20633)] = new TextVo(18, 5, 0, 1, 1);
            this.textMapDic[Language.getString(20634)] = new TextVo(19, 5, 0, 1, 1);
            this.textMapDic[Language.getString(20635)] = new TextVo(20, 5, 0, 1, 1);
            this.textMapDic[Language.getString(20636)] = new TextVo(21, 5, 0, 1, 1);
            this.textMapDic[Language.getString(20637)] = new TextVo(22, 5, 0, 1, 1);
            this.textMapDic[Language.getString(20638)] = new TextVo(23, 5, 0, 1, 1);
            this.textMapDic[Language.getString(20639)] = new TextVo(12, 6, 0, 1, 1);
            this.textMapDic[Language.getString(20640)] = new TextVo(13, 6, 0, 1, 1);
            this.textMapDic[Language.getString(20641)] = new TextVo(14, 6, 0, 2, 2);
            this.textMapDic[Language.getString(20642)] = new TextVo(14, 8, 0, 2, 1);
            this.textMapDic[Language.getString(20643)] = new TextVo(14, 9, 0, 2, 1);
            this.textMapDic[Language.getString(20644)] = new TextVo(14, 10, 0, 2, 1);
            this.textMapDic[Language.getString(20645)] = new TextVo(14, 11, 0, 2, 1);
            this.textMapDic[Language.getString(20646)] = new TextVo(14, 12, 0, 2, 1);
            this.textMapDic[Language.getString(20647)] = new TextVo(14, 13, 0, 2, 1);
            this.textMapDic[Language.getString(20648)] = new TextVo(14, 14, 0, 2, 1);
            this.textMapDic[Language.getString(20649)] = new TextVo(14, 15, 0, 2, 1);
            this.textMapDic[Language.getString(20650)] = new TextVo(14, 16, 0, 2, 1);
            this.textMapDic[Language.getString(20651)] = new TextVo(14, 17, 0, 2, 1);
            this.textMapDic[Language.getString(20652)] = new TextVo(14, 18, 0, 2, 1);
            this.textMapDic[Language.getString(20653)] = new TextVo(14, 19, 0, 2, 1);
            var _loc_5:* = TextVo.su;
            this.numberMapDic["0"] = 0 * _loc_5;
            this.numberMapDic["1"] = 1 * _loc_5;
            this.numberMapDic["2"] = 2 * _loc_5;
            this.numberMapDic["3"] = 3 * _loc_5;
            this.numberMapDic["4"] = 4 * _loc_5;
            this.numberMapDic["5"] = 5 * _loc_5;
            this.numberMapDic["6"] = 6 * _loc_5;
            this.numberMapDic["7"] = 7 * _loc_5;
            this.numberMapDic["8"] = 8 * _loc_5;
            this.numberMapDic["9"] = 9 * _loc_5;
            this.numberMapDic["-"] = 10 * _loc_5;
            this.numberMapDic["+"] = 11 * _loc_5;
            this.kuohaoMapDic["("] = new TextVo(12, 0, 1, 1, 1);
            this.kuohaoMapDic[")"] = new TextVo(13, 0, 1, 1, 1);
            var _loc_6:* = new Timer(20 * 1000);
            _loc_6.addEventListener(TimerEvent.TIMER, this.checkToDispose);
            _loc_6.start();
            return;
        }// end function

        private function checkToDispose(param1:Object) : void
        {
            var _loc_2:int = 0;
            var _loc_3:Stext3DBox = null;
            var _loc_4:Vector.<SText3D> = null;
            var _loc_5:Vector.<Stext3DPlace> = null;
            var _loc_6:int = 0;
            if (VcList.totalUseNum < SText3DRender.instance.maxNum && this.textMesh3d.vcListMap.length > 1)
            {
                this.textMesh3d.clearAll();
                _loc_2 = 0;
                while (_loc_2 < this._curUseBoxList.length)
                {
                    
                    _loc_3 = this._curUseBoxList[_loc_2];
                    _loc_4 = _loc_3.list;
                    _loc_5 = this.getPlaces((_loc_4.length + 1));
                    _loc_3.place = _loc_5[0];
                    _loc_6 = 0;
                    while (_loc_6 < _loc_4.length)
                    {
                        
                        _loc_4[_loc_6].reInitPlace(_loc_5[(_loc_6 + 1)], _loc_3.place);
                        _loc_6++;
                    }
                    _loc_2++;
                }
            }
            return;
        }// end function

        public function init(param1:GameScene3D) : void
        {
            this._scene = param1;
            param1.addChild(this.textMesh3d);
            this.textMesh3d.upload(param1);
            SText3DRender.instance.init(param1);
            return;
        }// end function

        public function reinit(param1:GameScene3D) : void
        {
            SText3DRender.instance.reinit(param1);
            return;
        }// end function

        private function getPlaces(param1:int) : Vector.<Stext3DPlace>
        {
            var _loc_3:VcList = null;
            if (this.tempVect.length < param1)
            {
                this.tempVect.length = param1;
            }
            var _loc_2:* = this.textMesh3d.vcListMap;
            for each (_loc_3 in _loc_2)
            {
                
                if (_loc_3.getPlaces(param1, this.tempVect))
                {
                    return this.tempVect;
                }
            }
            _loc_3 = this.textMesh3d.createNewVcList();
            _loc_3.getPlaces(param1, this.tempVect);
            return this.tempVect;
        }// end function

        private function stringReplacefun() : String
        {
            arguments = arguments;
            return this.textReplaceDic[arguments[0]];
        }// end function

        public function createtext3D(param1:String, param2:Number, param3:Pivot3D, param4:ActionVo, param5:Boolean = false) : Stext3DBox
        {
            var _loc_11:Number = NaN;
            var _loc_12:Number = NaN;
            var _loc_17:Boolean = false;
            var _loc_22:String = null;
            var _loc_23:TextVo = null;
            var _loc_24:SText3D = null;
            if (!Global3D.loadResource)
            {
                return null;
            }
            if (param4.type == 0 || param4.type == 1)
            {
                param1 = param1.replace(this.reg, this.stringReplacefun);
            }
            var _loc_6:* = param1.split("");
            if (param5)
            {
                _loc_6.unshift(Language.getString(20654));
            }
            var _loc_7:* = _loc_6.length;
            if (_loc_7 == 0)
            {
                return null;
            }
            var _loc_8:* = this._boxPool.length > 0 ? (this._boxPool.pop()) : (new Stext3DBox("stext3dbox"));
            var _loc_9:* = new Vector.<SText3D>;
            var _loc_10:* = param5 ? (ENumberTextColor.petPurple) : (param2);
            var _loc_13:uint = 0;
            var _loc_14:uint = 0;
            var _loc_15:int = 1;
            var _loc_16:int = 1;
            var _loc_18:Boolean = false;
            var _loc_19:* = this.getPlaces((_loc_7 + 1));
            var _loc_20:int = 0;
            while (_loc_20 < _loc_7)
            {
                
                _loc_22 = _loc_6[_loc_20];
                var _loc_25:* = this.textMapDic[_loc_22];
                _loc_23 = this.textMapDic[_loc_22];
                if (_loc_25)
                {
                    _loc_12 = _loc_23.u;
                    _loc_11 = _loc_23.v;
                    _loc_13 = _loc_23.width;
                    _loc_14 = _loc_23.height;
                    _loc_15 = _loc_20 == 0 ? (1) : (_loc_23.offsetX);
                    _loc_17 = false;
                }
                else
                {
                    var _loc_25:* = this.kuohaoMapDic[_loc_22];
                    _loc_23 = this.kuohaoMapDic[_loc_22];
                    if (_loc_25)
                    {
                        if (_loc_22 == "(" && !param5)
                        {
                            _loc_10 = ENumberTextColor.green0;
                        }
                        _loc_12 = _loc_23.u;
                        _loc_11 = _loc_10;
                        _loc_15 = 1;
                        _loc_13 = 1;
                        _loc_14 = 1;
                        _loc_17 = true;
                    }
                    else
                    {
                        _loc_12 = this.numberMapDic[_loc_22];
                        _loc_11 = _loc_10;
                        _loc_15 = 1;
                        _loc_13 = 1;
                        _loc_14 = 1;
                        _loc_17 = true;
                    }
                }
                if (_loc_18 && _loc_17)
                {
                    _loc_15 = _loc_15 + -8;
                }
                _loc_18 = _loc_17;
                _loc_16 = _loc_16 + _loc_15;
                _loc_24 = this._sText3DPool.length > 0 ? (this._sText3DPool.pop()) : (new SText3D(param1));
                _loc_24.reInitPlace(_loc_19[(_loc_20 + 1)], _loc_19[0]);
                _loc_24.setImgInfo(_loc_13, _loc_14, _loc_16, _loc_12, _loc_11);
                _loc_16 = _loc_16 + (_loc_17 ? (_loc_13 * TextVo.sw) : (_loc_13 * TextVo.sw + _loc_23.offsetX));
                _loc_9.push(_loc_24);
                _loc_20++;
            }
            var _loc_21:* = (-_loc_16) / 2;
            _loc_20 = 0;
            while (_loc_20 < _loc_7)
            {
                
                _loc_24 = _loc_9[_loc_20];
                _loc_24.setCenterPos(_loc_21);
                _loc_20++;
            }
            _loc_8.reInit(TimeControler.stageFrame, _loc_9, _loc_19[0], _loc_16, param3, param4);
            this._curUseBoxList.push(_loc_8);
            return _loc_8;
        }// end function

        public function disposeText3D(param1:Stext3DBox) : void
        {
            var _loc_3:SText3D = null;
            var _loc_4:int = 0;
            if (param1.parent)
            {
                param1.parent = null;
            }
            this._boxPool.push(param1);
            param1.clear(true);
            var _loc_2:* = param1.list;
            for each (_loc_3 in _loc_2)
            {
                
                if (this._sText3DPool.indexOf(_loc_3) == -1)
                {
                    this._sText3DPool.push(_loc_3);
                    _loc_3.clear();
                }
            }
            _loc_4 = this._curUseBoxList.indexOf(param1);
            this._curUseBoxList.splice(_loc_4, 1);
            return;
        }// end function

    }
}
